import request from '@/utils/request'
import axios from 'axios'

export function listproductProductions(data) {
  return request({
    url: '/productProduction/list',
    method: 'post',
    data
  })
}

export function setIsEnd(data) {
  return request({
    url: '/productProduction/setEnd',
    method: 'post',
    data
  })
}


export function listReportForms(data) {
  return request({
    url: '/reportForm/list',
    method: 'post',
    data
  })
}
export function listReportFormsYear(data) {
  return request({
    url: '/reportForm/byYear',
    method: 'post',
    data
  })
}
export function listReportFormsWeek(data) {
  return request({
    url: '/reportForm/byWeek',
    method: 'post',
    data
  })
}
export function listReportFormsDate(data) {
  return request({
    url: '/reportForm/byDate',
    method: 'post',
    data
  })
}
export function listReportFormsMonth(data) {
  return request({
    url: '/reportForm/byMonth',
    method: 'post',
    data
  })
}

export function listReportFormsBatch(data) {
  return request({
    url: '/reportForm/listByBatch',
    method: 'post',
    data
  })
}

export function listByOrders(query) {
  return request({
    url: '/productProduction/listByOrder',
    method: 'get',
    params: query
  })
}

export function listNewProduct(query) {
  return request({
    url: '/productProduction/list',
    method: 'get',
    params: query
  })
}

export function getInfoByOrderCount(query) {
  return request({
    url: '/productProduction/getInfoByOrderCounts',
    method: 'get',
    params: query
  })
}

export function deleteProductProductions(data) {
  return request({
    url: '/productProduction/deleteProductProduction',
    method: 'post',
    data
  })
}

export const uploadFileRequest = (url, params) => {
  return axios({
    method: 'post',
    url: '/productProduction/insertMany',
    data: params,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function publishproductProduction(query) {
  return request({
    url: '/productProduction/create',
    method: 'get',
    params: query
  })
}

export function getSortedList(sortField, sortOrder) {
  return request({
    url: '/productProduction/getSortedByDate',
    method: 'get',
    params: { sortField, sortOrder }
  })
}

export function insertAllproductProduction(data) {
  return request({
    url: '/productProduction/insertMany',
    method: 'post',
    data
  })
}

export function detailproductProduction(id) {
  return request({
    url: '/productProduction/detail',
    method: 'get',
    params: { id }
  })
}

export function detailproductInfo(data) {
  return request({
    url: '/iorder/queryProduction',
    method: 'post',
    data
  })
}

export function detailCF(data) {
  return request({
    url: '/iorder/queryCF',
    method: 'post',
    data
  })
}

export function createOrderList(data) {
  return request({
    url: '/iorder/queryListCount',
    method: 'post',
    data
  })
}
export function listBachNumbers(data) {
  return request({
    url: '/productProduction/queryBatchNumbers',
    method: 'post',
    data
  })
}
export function listBachNumbers2(data) {
  return request({
    url: '/productProduction/queryBatchNumbers2',
    method: 'post',
    data
  })
}

export function createStock(data) {
  return request({
    url: '/iorder/createStock',
    method: 'post',
    data
  })
}

export function catchTotalInfo(data) {
  return request({
    url: '/iorder/getTotalSheet',
    method: 'post',
    data
  })
}

export function createShipAccord(data) {
  return request({
    url: '/iorder/getShipAccord',
    method: 'post',
    data
  })
}

export function getOAsheet(data) {
  return request({
    url: '/iorder/getOAsheet',
    method: 'post',
    data
  })
}


export function getSplitSheet(data) {
  return request({
    url: '/iorder/getSplitSheet',
    method: 'post',
    data
  })
}


export function getSplitSheet2(data) {
  return request({
    url: '/iorder/getSplitSheet2',
    method: 'post',
    data
  })
}


export function editproductProduction(data) {
  return request({
    url: '/productProduction/update',
    method: 'post',
    data
  })
}
export function getStringAfter(str, after) {
  // 使用split方法以特定字符串为分隔符，并取第二部分
  return str.split(after)[1];
}
export function moreproductProduction(data) {
  return request({
    url: '/productProduction/more',
    method: 'post',
    data
  })
}

export function getValueByKey(keyValuePairs, keyToFind) {
  for (let i = 0; i < keyValuePairs.length; i++) {
    if (keyValuePairs[i].key === keyToFind) {
      return keyValuePairs[i].value;
    }
  }
  return null; // 如果找不到键，返回null
}

export function listCatAndBrand() {
  return request({
    url: '/productProduction/catAndBrand',
    method: 'get'
  })
}

export function myformatdate(inputTime) {
  if (!inputTime && typeof inputTime !== 'number') {
    return ''
  }
  var localTime = ''
  inputTime = new Date(inputTime).getTime()
  const offset = (new Date()).getTimezoneOffset()
  localTime = (new Date(inputTime - offset * 60000)).toISOString()
  localTime = localTime.substr(0, localTime.lastIndexOf('.'))
  localTime = localTime.replace('T', ' ')
  return localTime
}
export function formatterTime(row, column) {
  const data = row[column.property]
  return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data)
}

export function uploadFile(data) {
  return request({
    method: 'post',
    url: '/productProduction/insertMany',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
